package thread;

import java.util.Timer;
import java.util.TimerTask;

public class Demo27 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        // 这里相当于把任务放在TimerTask实例中，通过schedule方法将任务和执行时间提交到任务队列中
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer2000");
            }
        }, 2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer1000");
            }
        }, 1000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello timer3000");
            }
        }, 3000);
    }
}
